/* Simple test of process_create, process_wait race condition. */
/* This should never hang, unless the system is under incredibly high
   load and the child's PID is reused before we are rescheduled. */

#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

#include <sos.h>
#include <sel4/sel4.h>

int main(void){
    printf("Hi! I'm waitrace!\n");

    int i = 0;
    int pid;
    int ded;

    while (1) {
        printf("Spawning my %dth child process...\n", i++);
        pid = sos_process_create("tty_test");
        if (pid < 0) {
            printf("Failed to create process.\n");
            return 1;
        }
        ded = sos_process_wait(pid);
        printf("The process %d exited.\n", ded);
        assert(ded == pid);        
    }

    return 0;
}
